
/**
 * 
 * http://stackoverflow.com/questions/3911278/inherit-a-static-variable-in-java
 * http://stackoverflow.com/questions/685300/is-there-a-way-to-override-class-variables-in-java
 * http://download.oracle.com/javase/tutorial/java/IandI/index.html
 * 
 * java -cp bin StaticMethodInheritanceTest
 * 
 * @author david
 */
public class StaticMethodInheritanceTest
{
    public static void main(String[] args)
    {        
        Parent c1 = new ChildOne();
        Parent c2 = new ChildTwo();
        log("Child1: \t" + arrayToString(ChildOne.MY_CONST));
        log("Child1: \t" + arrayToString(new ChildOne().getConst()));
        log("Child1 as Parent: " + arrayToString(c1.getConst()));
        log("Child1 via dummy instance: " + arrayToString(ChildOne.INSTANCE.getConst()));
        
        log("Child2: \t" + arrayToString(ChildTwo.MY_CONST));
        log("Child2: \t" + arrayToString(new ChildTwo().getConst()));
        log("Child2 as Parent: " + arrayToString(c2.getConst()));
        log("Child2 via dummy instance: " + arrayToString(ChildTwo.INSTANCE.getConst()));
    }
    
    static abstract class Parent
    {
        public abstract Integer[] getConst();
    }

    static class ChildOne extends Parent
    {
        static public  final Integer[] MY_CONST = {7,8};
        static private final Parent    INSTANCE = new ChildOne(); 
        
        @Override public Integer[] getConst()    { return MY_CONST; }
    }
    
    static class ChildTwo extends Parent
    {
        static public  final Integer[] MY_CONST = {1,2};
        static private final Parent    INSTANCE = new ChildTwo();
        
        @Override public Integer[] getConst()    { return MY_CONST; }
    }
    
    
    static public String arrayToString(Integer[] array) {
        String out = "";
        for (int i = 0 ; i < array.length ; i++)
            out += " " + array[i];
        return out;
    }
    
    public static void log(String msg) {
        System.out.println(msg);
    }

}
